CFLAGS = -fpic -coverage -lm -std=c99

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

testsuite: testsuite.c dominion.o rngs.o unittest1.o unittest2.o unittest3.o unittest4.o cardtest1.o cardtest2.o cardtest3.o cardtest4.o
	gcc -o testsuite -g testsuite.c dominion.o rngs.o unittest1.o unittest2.o unittest3.o unittest4.o cardtest1.o cardtest2.o cardtest3.o cardtest4.o $(CFLAGS)

unittest1.o: unittest1.c unittest1.h dominion.o rngs.o
	gcc -c unittest1.c -g $(CFLAGS)

unittest2.o: unittest2.c unittest2.h dominion.o rngs.o
	gcc -c unittest2.c -g $(CFLAGS)

unittest3.o: unittest3.c unittest3.h dominion.o rngs.o
	gcc -c unittest3.c -g $(CFLAGS)

unittest4.o: unittest4.c unittest4.h dominion.o rngs.o
	gcc -c unittest4.c -g $(CFLAGS)

cardtest1.o: cardtest1.c cardtest1.h dominion.o rngs.o
	gcc -c cardtest1.c -g $(CFLAGS)

cardtest2.o: cardtest2.c cardtest2.h dominion.o rngs.o
	gcc -c cardtest2.c -g $(CFLAGS)

cardtest3.o: cardtest3.c cardtest3.h dominion.o rngs.o
	gcc -c cardtest3.c -g $(CFLAGS)

cardtest4.o: cardtest4.c cardtest4.h dominion.o rngs.o
	gcc -c cardtest4.c -g $(CFLAGS)

unittestresults.out: testsuite
	rm -f unittestresults.out
	./testsuite &> unittestresults.out
	gcov -b -c dominion.c >> unittestresults.out
	cat dominion.c.gcov >> unittestresults.out

randomtestadventurer: randomtestadventurer.c dominion.o rngs.o
	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS) -fno-stack-protector

randomtestadventurer.out: randomtestadventurer
	rm -f randomtestadventurer.out
	./randomtestadventurer &> randomtestadventurer.out
	gcov -b -c dominion.c >> randomtestadventurer.out
	cat dominion.c.gcov >> randomtestadventurer.out

randomtestcard: randomtestcard.c dominion.o rngs.o
	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)

randomtestcard.out: randomtestcard
	rm -f randomtestcard.out
	./randomtestcard &> randomtestcard.out
	gcov -b -c dominion.c >> randomtestcard.out
	cat dominion.c.gcov >> randomtestcard.out

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testsuite.c
	gcc -o testsuite testsuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

runtests: testDrawCard
	./testDrawCard &> unittestresult.out
	gcov dominion.c >> unittestresult.out
	cat dominion.c.gcov >> unittestresult.out

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

all: playdom player testDrawCard testBuyCard badTestDrawCard testsuite

clean:
	rm -f *.o playdom.exe playdom test.exe test testsuite randomtestadventurer randomtestcard player player.exe testInit testInit.exe badTestDrawCard testDrawCard *.gcov *.gcda *.gcno *.so *.out
	rm -fr *.dSYM

randomtestcard2: randomtestcard2.c randomutils.o dominion.o rngs.o
	gcc -o randomtestcard2 randomtestcard2.c -g randomutils.o dominion.o rngs.o $(CFLAGS)

randomutils.o: randomutils.h randomutils.c
	gcc -c randomutils.c -g $(CFLAGS)

randomtestcard2.out: randomtestcard2
	rm -f randomtestcard2.out
	./randomtestcard2 &> randomtestcard2.out
	gcov -b -c dominion.c >> randomtestcard2.out
	cat dominion.c.gcov >> randomtestcard2.out